/*
 * @Description: 在工作日志笔记头部自动插入星期和日期
 * @version:
 * @Author: tangxiaobin
 * @Date: 2020-07-13 10:53:35
 * @LastEditors: Please set LastEditors
 */
const dayjs = require("dayjs");
const weekday = require("dayjs/plugin/weekday")
require ("dayjs/locale/zh-cn")
// config dayjs
dayjs.extend(weekday);
dayjs.locale('zh-cn')

const writeFile = require("./writeFile");


function getFormateDate (date) {
   return date.format("MM.DD");
}

const weekEnum = {
   0: "一",
   1: "二",
   2: "三",
   3: "四",
   4: "五",
};

function main () {
   const firstDay = dayjs().startOf("year");
   const lastDay = dayjs().endOf("year");
   const weeks = lastDay.diff(firstDay, "week")+1;

   const arr = [];

   for (let i = 0; i < weeks; i++) {
      let weekStart = dayjs(firstDay.add(i * 7, "day")).startOf("week");
      let weekEnd = dayjs(firstDay.add(i * 7, "day")).endOf("week");

      const s = getFormateDate(weekStart);
      const e = getFormateDate(weekEnd);

      const range = `\n### ${i + 1}周(${s} ~ ${e})\n`;
      const weekDay = [...new Array(5).keys()].map(
         (j) => `#### 周${weekEnum[j]} ${getFormateDate(dayjs(weekStart).add(j, "day"))}\n1. `
      );

      arr.push(range + weekDay.join("\n"));
   }
   writeFile.writeFileToLine(arr.join(""), "./result.md");
}

main();
// const mdFilePath = 'D:\\softData\\qqC63C30C99A1E00DAD7EDE1E834114B3C\\B2D103F9959843EE938D49B1C43016A1\\工作日志.md'

// function getCurrentWeekDays(formate = 'YYYY-MM-DD') {
//    const startDate = moment()
//       .week(moment().week())
//       .startOf('isoweek')
//       .format(formate);
//    const endDate = moment()
//       .week(moment().week())
//       .endOf('isoweek')
//       .format(formate);
//    return [startDate, endDate];
// }

// let weekDay = getCurrentWeekDays('MM.DD').join('~');
// let week = moment().isoWeek(); // 数字

// let temp = `
// #### 第${week}周 ${weekDay}
// ##### 简要
// 1.

// ##### 详情
// 1. 周一
//    1.

// 2. 周二
//    1.

// 3. 周三
//    1.

// 4. 周四
//    1.

// 5. 周五
//    1.
// `

// writeFile.writeFileToLine(temp, mdFilePath)